package com.young.cms.web;

import com.young.cms.model.GenCol;
import com.young.cms.model.GenCreateMenuVO;
import com.young.cms.service.ICmsGenColService;
import com.young.cms.util.CmsConstants;
import com.young.common.core.excel.ExcelExport;
import com.young.common.core.excel.ExcelImport;
import com.young.common.core.excel.IExcelExport;
import com.young.common.core.excel.IExcelImport;
import com.young.common.exception.BaseException;
import com.young.common.util.*;
import com.young.common.core.dal.EDBType;
import com.young.common.core.dal.service.IDataAccessService;
import com.young.interfaces.log.annotation.Log;
import com.young.cms.model.GenMain;
import com.young.cms.service.ICmsGenMainService;
import com.young.interfaces.ums.model.User;
import com.young.common.client.ums.UmsClientHelper;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 代码生成主体信息服务
 * Created by rookie on 2018-04-03.
 */
@Controller
@RequestMapping(value = "/cms/genMain", method = {RequestMethod.GET, RequestMethod.POST})
public class CmsGenMainController {

    @Resource(name = "genMainService")
    ICmsGenMainService service;

    @Resource(name = "genColService")
    ICmsGenColService genColService;

    @Resource(name = "dataAccessService")
    IDataAccessService dataAccessService;//数据层服务

    private final static Logger logger = LoggerFactory.getLogger(CmsGenMainController.class);

    @Log("查询服务域名列表")
    @RequestMapping("/domainList")
    @ResponseBody
    public Object domainList(GenMain obj, HttpServletRequest request) throws Exception {
        List<Map<String, String>> list = new ArrayList<>();
        for (String domain : CmsConstants.DOMAIN_LIST) {
            Map<String, String> map = new HashMap<>();
            map.put("domain", domain);
            map.put("text", domain);
            list.add(map);
        }
        return Result.buildSuccess(list);
    }

    /**
     * 获取数据列表
     *
     * @param obj
     * @param request
     * @return
     * @throws Exception
     */
    @Log("查询代码生成主体信息列表")
    @RequestMapping("/getList")
    @ResponseBody
    public Object getList(GenMain obj, HttpServletRequest request) throws Exception {
        List<GenMain> list = service.getList(obj);
        return Result.buildSuccess(list);
    }

    /**
     * 获取分页数据
     *
     * @param obj
     * @param request
     * @return
     * @throws Exception
     */
    @Log("分页查询代码生成主体信息列表")
    @RequestMapping("/getPage")
    @ResponseBody
    public Object getPage(GenMain obj, HttpServletRequest request) throws Exception {
        Page page = CommonUtil.getPageFromRequest(request);
        List<GenMain> list = service.getPage(obj, page);
        page.setData(list);
        return page;
    }

    /**
     * 获取单条数据
     *
     * @param id
     * @param request
     * @return
     * @throws Exception
     */
    @Log("查询代码生成主体信息")
    @RequestMapping("/get")
    @ResponseBody
    public Object get(String id, HttpServletRequest request) throws Exception {
        GenMain obj = service.get(id);
        return Result.buildSuccess(obj);
    }

    /**
     * 统计数量
     *
     * @param obj
     * @param request
     * @return
     * @throws Exception
     */
    @Log("统计代码生成主体信息数量")
    @RequestMapping("/count")
    @ResponseBody
    public Object count(GenMain obj, HttpServletRequest request) throws Exception {
        return Result.buildSuccess(service.count(obj));
    }

    /**
     * 新增
     *
     * @param obj
     * @param request
     * @return
     * @throws Exception
     */
    @Log("新增代码生成主体信息")
    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(GenMain obj, HttpServletRequest request) throws Exception {
        User user = UmsClientHelper.getLoginUser();
        if (user != null) {
            obj.setCreateUserId(user.getId());
            obj.setCreateUserName(user.getName());
        }
        //获取字段配置信息
        String cols = request.getParameter("cols");
        if (StringUtils.isNotBlank(cols)) {
            //将字符串格式的信息转为list
            List<GenCol> colList = CommonJsonUtil.jsonStrArrToBeanList(cols, GenCol.class);
            obj.setColList(colList);
        }
        service.insert(obj);
        return Result.buildSuccess();
    }

    /**
     * 修改
     *
     * @param obj
     * @param request
     * @return
     * @throws Exception
     */
    @Log("修改代码生成主体信息")
    @RequestMapping("/update")
    @ResponseBody
    public Object update(GenMain obj, HttpServletRequest request) throws Exception {
        //获取字段配置信息
        String cols = request.getParameter("cols");
        if (StringUtils.isNotBlank(cols)) {
            //将字符串格式的信息转为list
            List<GenCol> colList = CommonJsonUtil.jsonStrArrToBeanList(cols, GenCol.class);
            obj.setColList(colList);
        }
        service.update(obj);
        return Result.buildSuccess();
    }

    /**
     * 删除
     *
     * @param ids
     * @param id
     * @param request
     * @return
     * @throws Exception
     */
    @Log("删除代码生成主体信息")
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String ids, String id, HttpServletRequest request) throws Exception {
        if (StringUtils.isNotBlank(ids)) {
            String[] idArr = ids.split(",");
            service.delete(idArr);
        } else if (StringUtils.isNotBlank(id)) {
            service.delete(id);
        } else {
            return Result.buildFail("删除失败:待删除编号无效!");
        }
        return Result.buildSuccess();
    }

    /**
     * 导入
     *
     * @param file
     * @param request
     * @return
     * @throws Exception
     */
    @Log("导入代码生成主体信息")
    @RequestMapping("/import")
    @ResponseBody
    public Object importExcel(MultipartFile file, HttpServletRequest request) throws Exception {
        try {
            if (file != null && !file.isEmpty()) {
                //excel导入处理,返回excel中的数据集合
                IExcelImport ei = new ExcelImport(file.getOriginalFilename(), file.getInputStream());//将文件转为ExcelImport对象
                //从excel读取数据
                List<GenMain> list = ei.getImportDataAsBean(GenMain.class);
                if (list != null && list.size() > 0) {
                    int num = service.batchInsert(list);//批量插入
                    return Result.buildSuccessInfo("成功导入数据" + num + "条!");
                } else {
                    return Result.buildFail("导入失败:excel解析后结果为空!");
                }
            } else {
                return Result.buildFail("导入失败:文件为空!");
            }
        } catch (Throwable t) {
            return Result.buildFail("导入失败!");
        }
    }

    /**
     * 导出
     *
     * @param obj      查询的参数
     * @param request
     * @param response
     * @throws Exception
     */
    @Log("导出代码生成主体信息")
    @RequestMapping("/export")
    public void exportExcel(GenMain obj, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<GenMain> list = service.getList(obj);
        if (list != null && list.size() > 0) {
            IExcelExport ee = new ExcelExport();
            ee.insertBeanList(list, GenMain.class);
            ee.write2Response(response, "excel_" + System.currentTimeMillis() + ".xls");
        } else {
            response.getWriter().write("数据为空!");
        }
    }

    /**
     * 预览代码
     *
     * @param type  代码类型
     * @param genId 编号
     * @return
     */
    @Log("预览代码")
    @RequestMapping("/preview/{type}/{genId}")
    @ResponseBody
    public Object preview(@PathVariable("type") String type, @PathVariable("genId") String genId, HttpServletResponse response) {
        if (StringUtils.isBlank(genId) || StringUtils.isBlank(type)) {
            return Result.buildFail("代码生成编号或代码类型不允许为空");
        }
        //查询相关配置
        GenMain genMain = service.get(genId);
        if (genMain == null) {
            return Result.buildFail("未找到代码生成配置");
        } else if (StringUtils.isBlank(genMain.getPackageName()) || StringUtils.isBlank(genMain.getModuleName())) {
            //包名和模块名不允许为空
            return Result.buildFail("包名和模块名不允许为空");
        } else if (StringUtils.isBlank(genMain.getTableName())) {
            return Result.buildFail("表名不允许为空");
        } else if (StringUtils.isBlank(genMain.getSavePath())) {
            return Result.buildFail("代码保存路径不允许为空");
        } else {

            // 填充代码生成模板参数
            this.fillTemplateParam(genMain);

            //将配置信息放入map,在ftl中使用
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("model", genMain);
            map.put("primaryKeyType", genMain.getPrimaryKeyJavaType());

            //生成实体类
            Configuration configuration = new Configuration();
            configuration.setClassForTemplateLoading(this.getClass(), "/template/gen/");

            //生成
            try {
                Template template = configuration.getTemplate(type + ".ftl", "UTF-8");
                Writer fw = new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
                template.process(map, fw);
                fw.flush();
                fw.close();
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            } catch (TemplateException e) {
                return Result.buildFail("写入文件失败");
            }

        }
        return Result.buildSuccess();
    }

    /**
     * 填充代码生成模板参数
     *
     * @param genMain
     */
    private void fillTemplateParam(GenMain genMain) {
        //使用当前时间作为创建时间,用来生成注释的时候使用
        genMain.setCreateTime(new Date());

        //查询字段配置
        GenCol genCol = new GenCol();
        genCol.setGenId(genMain.getId());
        List<GenCol> colList = genColService.getList(genCol);
        genMain.setColList(colList);
        if (CollectionUtil.isEmpty(colList)) {
            throw new BaseException("未找到字段信息!");
        }

        //格式化字段类型,改为java中的类型
        for (GenCol col : genMain.getColList()) {
            // 转换字段的java类型
            col.convertFieldJavaType();

            // 主键类型
            if ("id".equalsIgnoreCase(col.getFieldName())) {
                genMain.setPrimaryKeyJavaType(col.getFieldType());
            }
        }

        //类名为空时,自动生成类名
        if (StringUtils.isBlank(genMain.getClassName())) {
            genMain.convertClassName();
        }
    }

    /**
     * 代码生成
     *
     * @param genId   代码生成编号
     * @param request
     * @return
     */
    @Log("代码生成")
    @RequestMapping("/generate/{genId}")
    @ResponseBody
    public Object generate(@PathVariable("genId") String genId, HttpServletRequest request) {
        if (StringUtils.isBlank(genId)) {
            return Result.buildFail("代码生成编号不允许为空");
        }
        //查询相关配置
        GenMain genMain = service.get(genId);
        if (genMain == null) {
            return Result.buildFail("未找到代码生成配置");
        } else if (StringUtils.isBlank(genMain.getPackageName()) || StringUtils.isBlank(genMain.getModuleName())) {
            //包名和模块名不允许为空
            return Result.buildFail("包名和模块名不允许为空");
        } else if (StringUtils.isBlank(genMain.getTableName())) {
            return Result.buildFail("表名不允许为空");
        } else if (StringUtils.isBlank(genMain.getSavePath())) {
            return Result.buildFail("代码保存路径不允许为空");
        } else {

            // 填充代码生成模板参数
            this.fillTemplateParam(genMain);

            //生成文件目录
            String rootPath = genMain.getSavePath();//"C:\\Users\\Administrator\\Desktop\\generate";//根目录
            String packagePath = rootPath + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator + genMain.getPackageName().replace(".", File.separator) + File.separator + genMain.getModuleName();
            //资源目录,用来放配置文件和mapper文件
            String resourcePath = rootPath + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + genMain.getPackageName().replace(".", File.separator) + File.separator + genMain.getModuleName();
            String pagePath = rootPath + File.separator + "src" + File.separator + "main" + File.separator + "webapp" + File.separator + "page" + File.separator + genMain.getModuleName();//jsp存放目录
            String path_model = packagePath + File.separator + "model";
            String path_service = packagePath + File.separator + "service";
            String path_service_impl = packagePath + File.separator + "service" + File.separator + "impl";
            String path_util = packagePath + File.separator + "util";
            String path_web = packagePath + File.separator + "web";
            String path_mapper;
            if (dataAccessService.getDBType() == EDBType.MYSQL) {
                path_mapper = resourcePath + File.separator + "mapper" + File.separator + "mysql";
            } else if (dataAccessService.getDBType() == EDBType.ORACLE) {
                path_mapper = resourcePath + File.separator + "mapper" + File.separator + "oracle";
            } else if (dataAccessService.getDBType() == EDBType.POSTGRESQL) {
                path_mapper = resourcePath + File.separator + "mapper" + File.separator + "postgres";
            } else {
                return Result.buildFail("数据库类型不匹配");
            }
            String[] dirs = {path_model, path_service, path_service_impl, path_util, path_web, path_mapper, pagePath};
            //创建各目录
            for (String dir : dirs) {
                File f = new File(dir);
                if (!f.exists()) {//不存在此目录,则创建
                    f.mkdirs();
                    logger.info("[代码生成] 成功创建目录: {}", f.getAbsolutePath());
                }
            }

            //将配置信息放入map,在ftl中使用
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("model", genMain);
            map.put("primaryKeyType", genMain.getPrimaryKeyJavaType());

            //生成实体类
            Configuration configuration = new Configuration();
            configuration.setClassForTemplateLoading(this.getClass(), "/template/gen/");
            try {
                Template template = configuration.getTemplate("Model.ftl", "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(path_model + File.separator + model.getClassName()+".java"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path_model + File.separator + genMain.getClassName() + ".java"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建实体类: {}", genMain.getClassName() + ".java");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }

            //生成Mapper.xml映射文件
            try {
                Template template = configuration.getTemplate("Mapper.ftl", "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(path_mapper + File.separator + model.getClassName()+"Mapper.xml"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path_mapper + File.separator + genMain.getClassName() + "Mapper.xml"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建Mapper.xml: {}", genMain.getClassName() + "Mapper.xml");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }

            //生成service接口
            try {
                Template template = configuration.getTemplate("Service.ftl", "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(path_service + File.separator + "I" + model.getClassName()+"Service.java"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path_service + File.separator + "I" + genMain.getClassName() + "Service.java"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建service接口: {}", "I" + genMain.getClassName() + "Service.java");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }

            //生成serviceImpl服务实现类
            try {
                Template template = configuration.getTemplate("ServiceImpl.ftl", "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(path_service_impl + File.separator + model.getClassName()+"ServiceImpl.java"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path_service_impl + File.separator + genMain.getClassName() + "ServiceImpl.java"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建service实现类: {}", genMain.getClassName() + "ServiceImpl.java");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }

            //生成controller
            try {
                Template template = configuration.getTemplate("Controller.ftl", "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(path_web + File.separator + model.getClassName()+"Controller.java"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path_web + File.separator + genMain.getClassName() + "Controller.java"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建Controller类: {}", genMain.getClassName() + "Controller.java");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }

            //生成视图页
            //对字段配置按照视图显示顺序排序
            Collections.sort(genMain.getColList(), new Comparator<GenCol>() {
                @Override
                public int compare(GenCol o1, GenCol o2) {
                    if (o1.getViewNum() != null && o2.getViewNum() != null) {
                        if (o1.getViewNum() > o2.getViewNum()) {
                            return 1;
                        } else if (o1.getViewNum() < o2.getViewNum()) {
                            return -1;
                        }
                    }
                    return 0;
                }
            });
            try {
                Template template = configuration.getTemplate("List.ftl", "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(pagePath + File.separator + model.getClassName().substring(0,1).toLowerCase()+model.getClassName().substring(1) + "List.jsp"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(pagePath + File.separator + genMain.getClassName().substring(0, 1).toLowerCase() + genMain.getClassName().substring(1) + "List.html"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建视图页: {}", genMain.getClassName().substring(0, 1).toLowerCase() + genMain.getClassName().substring(1) + "List.html");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }

            //生成表单页
            //将在表单显示的字段筛选出来
            List<GenCol> list2 = new ArrayList<GenCol>();
            for (GenCol genCol1 : genMain.getColList()) {
                if ("1".equals(genCol1.getFormShow())) {
                    list2.add(genCol1);
                }
            }
            genMain.setColList(list2);//将在表单显示的字段放进去
            //对字段配置按照表单显示顺序排序
            Collections.sort(genMain.getColList(), new Comparator<GenCol>() {
                @Override
                public int compare(GenCol o1, GenCol o2) {
                    if (o1.getFormNum() != null && o2.getFormNum() != null) {
                        if (o1.getFormNum() > o2.getFormNum()) {
                            return 1;
                        } else if (o1.getFormNum() < o2.getFormNum()) {
                            return -1;
                        }
                    }
                    return 0;
                }
            });
            try {
                String form = "Form.ftl";
                //选择使用的表单模板,以排序后的第一个字段配置为准
                if (genMain.getColList() != null && genMain.getColList().size() > 0) {
                    if ("2".equals(genMain.getColList().get(0).getControlClass())) {//2.0版本表单
                        form = "Form_2.ftl";
                    }

                }
                Template template = configuration.getTemplate(form, "UTF-8");//Locale.CHINA,
                try {
                    //FileWriter fw = new FileWriter(new File(pagePath + File.separator + model.getClassName().substring(0,1).toLowerCase()+model.getClassName().substring(1) + "Form.jsp"));
                    Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(pagePath + File.separator + genMain.getClassName().substring(0, 1).toLowerCase() + genMain.getClassName().substring(1) + "Form.html"), "UTF-8"));
                    template.process(map, fw);
                    fw.flush();
                    fw.close();
                    logger.info("[代码生成] 成功创建表单页: {}", genMain.getClassName().substring(0, 1).toLowerCase() + genMain.getClassName().substring(1) + "Form.html");
                } catch (TemplateException e) {
                    return Result.buildFail("写入文件失败");
                }
            } catch (IOException e) {
                return Result.buildFail("获取模板失败");
            }
        }
        return Result.buildSuccess();
    }

    /**
     * 备份代码生成配置
     *
     * @param ids      待备份配置的id,多个之间使用逗号间隔
     * @param request
     * @param response
     * @throws Exception
     */
    @Log("备份代码生成配置")
    @RequestMapping("/backup")
    public void backup(String ids, HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (StringUtils.isNotBlank(ids)) {
            String[] idArr = ids.split(",");
            if (idArr != null && idArr.length > 0) {
                List<GenMain> list = new ArrayList<GenMain>();
                for (String id : idArr) {
                    GenMain genMain = service.getFullGen(id);
                    if (genMain != null) {
                        list.add(genMain);
                    }
                }
                //备份
                if (list != null && list.size() > 0) {
                    //解析为json字符串
                    String str = CommonJsonUtil.beanListToJsonStrArr(list);
                    logger.info("[备份代码生成配置] 备份内容:{}", str);
                    //将json串写入流中供下载
                    byte[] bytes = str.getBytes("UTF-8");
                    //ByteInputStream byteInputStream = new ByteInputStream(bytes, bytes.length);
                    //下载处理
                    //FileDownloadUtil.downloadHandle(byteInputStream, DateUtil.dateFormat(new Date(), "yyyyMMddHHmmss")+".gen", request, response);
                    response.setContentType("application/x-msdownload;");//文件下载类型
                    FileDownloadUtil.setFileNameOfCN(request, response, DateUtil.dateFormat(new Date(), "yyyyMMddHHmmss") + ".gen");//设置中文文件名
                    OutputStream os = response.getOutputStream();
                    os.write(bytes);
                    os.close();
                }
            }
        }
    }

    /**
     * 恢复代码生成配置
     *
     * @param file
     * @param request
     * @param response
     * @throws Exception
     */
    @Log("恢复代码生成配置")
    @RequestMapping("/recover")
    @ResponseBody
    public Object recover(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (file != null && !file.isEmpty()) {
            InputStream is = file.getInputStream();
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            IOUtils.copy(is, byteArrayOutputStream);
            byte[] bytes = byteArrayOutputStream.toByteArray();
            String str = new String(bytes, "UTF-8");
            logger.info("[恢复代码生成配置] 恢复内容:{}", str);
            List<JSONObject> list = CommonJsonUtil.jsonStrArrToBeanList(str, JSONObject.class);
            //List<GenMain> list = CommonJsonUtil.jsonStrArrToBeanList(str, GenMain.class);
            //List<GenMain> list = CommonJsonUtil.jsonStr2Bean(str, List.class);
            if (list != null && list.size() > 0) {
                Map<String, Class> map = new HashMap<String, Class>();
                map.put("colList", GenCol.class);
                for (JSONObject jsonObject : list) {
                    GenMain genMain = (GenMain) JSONObject.toBean(jsonObject, GenMain.class, map);
                    service.insert(genMain);
                }
                //service.batchInsert(list);
            }
        }
        return Result.buildSuccess();
    }

    @Log("快捷创建菜单")
    @RequestMapping("/createMenu")
    @ResponseBody
    public Object createMenu(GenCreateMenuVO genMenu) {
        AssertUtil.notBlank(genMenu.getName(), "菜单名称不允许为空");
        AssertUtil.notBlank(genMenu.getHref(), "链接不允许为空");
        service.createMenu(genMenu);
        return Result.buildSuccess();
    }

    @Log("同步字段变化")
    @RequestMapping("/syncFieldChange")
    @ResponseBody
    public Object syncFieldChange(String genId) {
        AssertUtil.notBlank(genId, "代码生成ID不允许为空");
        service.syncFieldChange(genId);
        return Result.buildSuccess();
    }

}